

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="CodeHope">
  <meta name="author" content="CodeHope">
  <meta name="keywords" content="希望">
  <title>SpringBoot控制器自动根据所在目录配置prefix - CodeHope</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      
        
          
          
          
        
        <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.22.0/themes/prism-tomorrow.min.css" />
      
      
        <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.22.0/plugins/line-numbers/prism-line-numbers.min.css" />
      
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"quancundexiwang.wang","root":"/","version":"1.8.7","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":true,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"onlypost":true},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"Mi65hxq7VAFUDwOLeIGAOgiV-gzGzoHsz","app_key":"hMuhiD4FRqhns4giqLiEH9HG","server_url":null}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.3.0"></head>


<body>
  <header style="height: 80vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>CodeHope</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                村头
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                我
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('http://qiniuyun.quancundexiwang.wang/20210502162555.png') repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="SpringBoot控制器自动根据所在目录配置prefix">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-05-02 16:28" pubdate>
        2021年5月2日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.1k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      13
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
            <div class="scroll-down-bar">
              <i class="iconfont icon-arrowdown"></i>
            </div>
          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">SpringBoot控制器自动根据所在目录配置prefix</h1>
            
            <div class="markdown-body">
              <h1 id="SpringBoot控制器自动根据所在目录配置prefix"><a href="#SpringBoot控制器自动根据所在目录配置prefix" class="headerlink" title="SpringBoot控制器自动根据所在目录配置prefix"></a><code>SpringBoot</code>控制器自动根据所在目录配置<code>prefix</code></h1><h2 id="1-Why-为什么要这么做！"><a href="#1-Why-为什么要这么做！" class="headerlink" title="1. Why 为什么要这么做！"></a>1. Why 为什么要这么做！</h2><p> 发现我们在写接口的时候，比如对接的是一个客户端程序，【这里考虑客户端是因为，客户端用户可能会有对客户端更新或者不更新的权利】，可能经常要分版本写接口，比如有的接口在最新版本进行了更新，但是有的客户用的还是旧版的客户端，那么此时你两套接口都要维护，不能因为客户不更新，然后他的旧版本对接的那套接口就用不了了！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210501192018617.png" srcset="/img/loading.gif" alt="image-20210501192018617"></p>
<p>一般我们会在控制器类上设置一个<code>prefix</code>,比如上面那样子，这样出来的请求就是<a target="_blank" rel="noopener" href="http://localhost:8080/v1/queryListCmd">http://localhost:8080/v1/queryListCmd</a></p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210501192255658.png" srcset="/img/loading.gif" alt="image-20210501192255658"></p>
<p>   此章节的目的！就是控制器类能根据所在的包下！根据包名自动生成<code>prefix</code></p>
<h2 id="2-How-怎么做？"><a href="#2-How-怎么做？" class="headerlink" title="2. How 怎么做？"></a>2. How 怎么做？</h2><h3 id="a-修改默认的MappingInfo生成方式"><a href="#a-修改默认的MappingInfo生成方式" class="headerlink" title="a).  修改默认的MappingInfo生成方式"></a>a).  修改默认的<code>MappingInfo</code>生成方式</h3><p>首先我们回顾一下控制器的<code>@RequestMapping</code>,Spring通过扫描到<code>@RequestMapping</code>注解，将所有的控制器对应URL以key-value的形式放入一个map集合中</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502125859225.png" srcset="/img/loading.gif" alt="image-20210502125859225"></p>
<p>那么我们就可以在放入map集合之前对这个键（也就是我们最终匹配的URI）根据我们的当前的文件夹目录，自动的嵌入前缀！</p>
<p>首先我们认识一下这个类 <code>RequestMappingHandlerMapping</code>这个类就是用来处理生成我们最终那个map集合的类！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502130448020.png" srcset="/img/loading.gif" alt="image-20210502130448020"></p>
<p>然后里面有一个关键的方法！<code>getMappingForMethod</code> 使用方法和类型级别的<code>@RequestMapping</code>注解创建<code>RequestMappingInfo</code>。</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502140404896.png" srcset="/img/loading.gif" alt="image-20210502140404896"></p>
<p>参数 </p>
<ul>
<li><code>method</code> 是控制处理器的对应的方法！</li>
<li><code>handlerType</code> 是对应的控制器的类！</li>
</ul>
<p>返回值:<code>创建的RequestMappingInfo；</code>如果该方法没有<code>@RequestMapping</code>批注，则为<code>null。</code></p>
<p>这个返回的其实就是某一个注解标记的controller，里面包含了URL</p>
<p>那么我们就是要去继承这个类！去修改这个类的默认机制！去改写返回的<code>RequestMappingInfo</code>的URL,返回我们需要的一个<code>RequestMappingInfo</code></p>
<p> 我们知道了<code>handlerType</code>其实就是控制器的类！那么我们可以通过这个类获得其全路径类名！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502141342504.png" srcset="/img/loading.gif"></p>
<p><code>AutoPrefixConfiguration.java</code></p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502151239084.png" srcset="/img/loading.gif" alt="image-20210502151239084"></p>
<p>关于这个<code>v1</code>如何更好的配置进入代码，我们最后在看！这里先写死在这里，让我们对<code>RequestMappingInfo</code>的修改先生效再说！</p>
<p>到这一步！我们试一下！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502151816475.png" srcset="/img/loading.gif" alt="image-20210502151816475"></p>
<p>发现并没有生效！为什么呢？</p>
<p>因为还缺少一步！因为在<code>springboot</code>中这个<code>RequestMappingHandlerMapping</code>类,只是编写对<code>mappingInfo</code>的操作,</p>
<h3 id="b-将Mvc中操作Mapping的类改为自定义的类"><a href="#b-将Mvc中操作Mapping的类改为自定义的类" class="headerlink" title="b). 将Mvc中操作Mapping的类改为自定义的类"></a>b). 将<code>Mvc</code>中操作Mapping的类改为自定义的类</h3><p>我们也要去指定<code>springboot</code>去使用我们自定义的类去操作request mapping info,所以我们也需要修改<code>springboo</code>t默认处理mapping的类！</p>
<p><code>CoverMvcRequestMappingInfoType.java</code></p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502152217824.png" srcset="/img/loading.gif" alt="image-20210502152217824"></p>
<p>这个类加上了<code>@Component</code>标签，因为spring要在工程中找到我们自定义的类！然后发现覆盖了默认的接口实现类！这样就会使用我们的方式去处理了</p>
<p>这次我们再试一试！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502152403427.png" srcset="/img/loading.gif" alt="image-20210502152403427"></p>
<p>这样就可以了！</p>
<h3 id="c-完善那个prefix的获取"><a href="#c-完善那个prefix的获取" class="headerlink" title="c). 完善那个prefix的获取"></a>c). 完善那个prefix的获取</h3><p>我们之前这里是写死的！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502153521726.png" srcset="/img/loading.gif" alt="image-20210502153521726"></p>
<p>首先我们可以先在配置文件中写好我们控制器所在的包！放在配置文件中，不让一些可变的东西耦合在代码里面</p>
<div class="code-wrapper"><pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token attr-name">apiPackage</span><span class="token punctuation">:</span> <span class="token attr-value">com.codehope.ch.controllers</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502160026226.png" srcset="/img/loading.gif" alt="image-20210502160026226"></p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502160142241.png" srcset="/img/loading.gif" alt="image-20210502160142241"></p>
<p>读取配置文件的值！<code>com.codehope.ch.controllers</code>,将通过类获得的全类名，截取剩余<code>.api.v1</code>/<code>.api.v2</code>然后使用<code>/</code>替换<code>.</code></p>
<p>测试使用！</p>
<p><img src="http://qiniuyun.quancundexiwang.wang/image-20210502160356440.png" srcset="/img/loading.gif" alt="image-20210502160356440"></p>
<p>搞定！</p>
<h2 id="3-完整代码！"><a href="#3-完整代码！" class="headerlink" title="3. 完整代码！"></a>3. 完整代码！</h2><p><code>application.properties</code> 配置控制器的包路径【用于prefix】</p>
<div class="code-wrapper"><pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token attr-name">apiPackage</span><span class="token punctuation">:</span> <span class="token attr-value">com.codehope.ch.controllers</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p><code>AutoPrefixConfiguration.java</code> 自定义<code>RequestionMapping</code>对象</p>
<div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">package</span> <span class="token namespace">com<span class="token punctuation">.</span>codehope<span class="token punctuation">.</span>ch<span class="token punctuation">.</span>config</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>factory<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">Value</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">Configuration</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">PropertySource</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>servlet<span class="token punctuation">.</span>mvc<span class="token punctuation">.</span>method<span class="token punctuation">.</span></span><span class="token class-name">RequestMappingInfo</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>servlet<span class="token punctuation">.</span>mvc<span class="token punctuation">.</span>method<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">RequestMappingHandlerMapping</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> <span class="token namespace">java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>reflect<span class="token punctuation">.</span></span><span class="token class-name">Method</span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Configuration</span>
<span class="token annotation punctuation">@PropertySource</span><span class="token punctuation">(</span><span class="token string">"classpath:application.yml"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AutoPrefixConfiguration</span> <span class="token keyword">extends</span> <span class="token class-name">RequestMappingHandlerMapping</span> <span class="token punctuation">&#123;</span>
    <span class="token annotation punctuation">@Value</span><span class="token punctuation">(</span><span class="token string">"$&#123;apiPackage&#125;"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> apiPackage<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token class-name">RequestMappingInfo</span> <span class="token function">getMappingForMethod</span><span class="token punctuation">(</span><span class="token class-name">Method</span> method<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">></span></span> handlerType<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

        <span class="token class-name">RequestMappingInfo</span> requestMappingInfo <span class="token operator">=</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">getMappingForMethod</span><span class="token punctuation">(</span>method<span class="token punctuation">,</span> handlerType<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>requestMappingInfo <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token class-name">String</span> prefix <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getPrefix</span><span class="token punctuation">(</span>handlerType<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token class-name">RequestMappingInfo</span><span class="token punctuation">.</span><span class="token function">paths</span><span class="token punctuation">(</span>prefix<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">combine</span><span class="token punctuation">(</span>requestMappingInfo<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token keyword">private</span> <span class="token class-name">String</span> <span class="token function">getPrefix</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">></span></span> handlerType<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">//通过 Class&lt;?> handlerType这个类！可以拿到这个类所在的包</span>
        <span class="token class-name">String</span> packageName <span class="token operator">=</span> handlerType<span class="token punctuation">.</span><span class="token function">getPackageName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> packageName<span class="token punctuation">.</span><span class="token function">replaceAll</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>apiPackage<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">replaceAll</span><span class="token punctuation">(</span><span class="token string">"\\."</span><span class="token punctuation">,</span> <span class="token string">"/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p><code>CoverMvcRequestMappingInfoType.java</code> 覆盖<code>MVC</code>注册(<code>WebMvcRegistrations</code>)的<code>RequestMapping</code>处理器类！换成自定义的类！这样就可以使用自定义的Mapping对象！</p>
<div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">package</span> <span class="token namespace">com<span class="token punctuation">.</span>codehope<span class="token punctuation">.</span>ch<span class="token punctuation">.</span>core</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> <span class="token namespace">com<span class="token punctuation">.</span>codehope<span class="token punctuation">.</span>ch<span class="token punctuation">.</span>config<span class="token punctuation">.</span></span><span class="token class-name">AutoPrefixConfiguration</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>autoconfigure<span class="token punctuation">.</span>web<span class="token punctuation">.</span>servlet<span class="token punctuation">.</span></span><span class="token class-name">WebMvcRegistrations</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>stereotype<span class="token punctuation">.</span></span><span class="token class-name">Component</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>servlet<span class="token punctuation">.</span>mvc<span class="token punctuation">.</span>method<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">RequestMappingHandlerMapping</span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CoverMvcRequestMappingInfoType</span> <span class="token keyword">implements</span> <span class="token class-name">WebMvcRegistrations</span> <span class="token punctuation">&#123;</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">RequestMappingHandlerMapping</span> <span class="token function">getRequestMappingHandlerMapping</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span>  <span class="token keyword">new</span> <span class="token class-name">AutoPrefixConfiguration</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p>大功告成！</p>
<img src='http://qiniuyun.quancundexiwang.wang/0c8e100ba80f15ed321145a91d7afee8.gif' />


            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/Java/">Java</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/SpringBoot%E5%9F%BA%E7%A1%80/">SpringBoot基础</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/posts/1615/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">SpringBoot 接收请求参数相关</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/posts/53229/">
                        <span class="hidden-mobile">SpringBoot全局异常处理</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments">
                
                
  <div id="vcomments"></div>
  <script type="text/javascript">
    Fluid.utils.waitElementVisible('vcomments', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "Mi65hxq7VAFUDwOLeIGAOgiV-gzGzoHsz",
          app_key: "hMuhiD4FRqhns4giqLiEH9HG",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: false,
          recordIP: false,
          serverURLs: "",
        });
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the
    <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments powered by Valine.</a>
  </noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
    

  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        豫ICP备20009912号-1
      </a>
    </span>
    
  </div>


  
</footer>

<!-- SCRIPTS -->

  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":true,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    
      <script  src="/js/lazyload.js" ></script>
    
  



  
    
  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.0/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "http://qiniuyun.quancundexiwang.wang/xmlSearch.xml";
      var inputArea = document.querySelector("#local-search-input");
      inputArea.onclick = function () {
        searchFunc(path, 'local-search-input', 'local-search-result');
        this.onclick = null
      }
    })()
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>



</body>
</html>
